import time
import pymysql
import json

# 创建数据库连接
con = pymysql.connect(host="master", port=3306, user="root", passwd="123456", db="szt")
cursor = con.cursor()
# 读取文件
with open("G:\\LanZhiPeiXun\\Flink\\data\\szt_data.json", mode='r', encoding='utf-8') as f:
    while True:
        line = f.readline().strip()
        data = json.loads(line)
        print(data)

        try:
            cursor.execute(
                "insert into szt_data values(%(car_no)s,%(card_no)s,%(close_date)s,%(company_name)s,%(conn_mark)s,%(deal_date)s,%(deal_money)s,%(deal_type)s,%(deal_value)s,%(equ_no)s,%(station)s)",
                data)
            con.commit()
            time.sleep(0.001)
        except Exception as e:
            print(e)
